﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace GetData.webProductClass
{
    public class ProductTypeEnum
    {
        /// <summary>
        /// 定义枚举 获取留住你网站商品分类
        /// </summary>
        public enum liuzhuniType
        {
            电脑办公 = 1,
            手机数码 = 2,
            家用电器 = 3,
            服饰鞋帽 = 4,
            个护化妆 = 6,
            母婴用品 = 7,
            家居生活 = 8,
            食品酒水 = 10,
            图书音像 = 14,
            其他分类 = 16
        }
        /// <summary>
        /// 定义枚举 获取一分网站商品分类
        /// </summary>
        public enum yifenType
        {
            家电数码 = 3,
            服装鞋包 = 4,
            珠宝首饰 = 5,
            美容个护 = 6,
            母婴玩具 = 7,
            家居生活 = 8,
            食品保健 = 10,
            旅游户外 = 11,
            图书音像 = 14,
            其他分类 = 16
        }
        /// <summary>
        /// 定义枚举 获取smzdm商品分类
        /// </summary>
        public enum smzdmType
        {
            办公设备 = 1,
            电脑数码 = 2,
            家用电器 = 3,
            服饰鞋包 = 4,
            礼品钟表 = 5,
            个护化妆 = 6,
            母婴用品 = 7,
            家居家装 = 8,
            日用百货 = 9,
            食品保健 = 10,
            运动户外 = 11,
            汽车用品 = 12,
            玩模乐器 = 13,
            图书音像 = 14,
            其他分类 = 16
        }
        /// <summary>
        /// 定义枚举 获取mdb商品分类
        /// </summary>
        public enum mdbType
        {
            办公文具 = 1,
            C数码 = 2,
            家用电器 = 3,
            服饰箱包 = 4,
            钟表镜饰 = 5,
            个护化妆 = 6,
            母婴玩具 = 7,
            家居家装 = 8,
            日用百货 = 9,
            食品保健 = 10,
            运动户外 = 11,
            汽车用品 = 12,
            文化产物 = 14,
            其他分类 = 16
        }
        /// <summary>
        /// 定义枚举 获取瓦拉淘商品分类
        /// </summary>
        public enum walataoType
        {
            办公工艺 = 1,
            电脑数码 = 2,
            家用电器 = 3,
            服饰鞋表 = 4,
            钟表镜饰 = 5,
            个护化妆 = 6,
            母婴用品 = 7,
            日用百货 = 9,
            食品保健 = 10,
            运动户外 = 11,
            汽车用品 = 12,
            玩模乐器 = 13,
            图书数字 = 14,
            其他 = 16
        }
        /// <summary>
        /// 定义枚举 获取慧慧网商品分类
        /// </summary>
        public enum huihuiType
        {
            数码家电 = 3,
            服饰鞋包 = 4,
            美妆个护 = 6,
            母婴玩具 = 7,
            日用百货 = 9,
            食品生鲜 = 10,
            运动健康 = 11,
            文化娱乐 = 13,

            其他类别 = 16
        }
        /// <summary>
        /// 定义枚举 获取超值分享汇商品分类
        /// </summary>
        public enum cxfxhType
        {
            电脑办公 = 1,
            手机数码 = 2,
            家用电器 = 3,
            服饰鞋包 = 4,
            钟表珠宝 = 5,
            个护化妆 = 6,
            日用百货 = 9,
            食品饮料 = 10,

            图书音像 = 14,
            其他分类 = 16
        }
        /// <summary>
        /// 定义枚举 获取天上掉馅饼汇商品分类
        /// </summary>
        public enum tsdxbType
        {
            手机数码 = 2,
            家用电器 = 3,
            服饰鞋帽 = 4,
            个护化妆 = 6,
            孕婴童 = 7,
            家居生活 = 8,
            食品饮料 = 10,
            汽车用品 = 12,
            其他 = 16
        }

        /// <summary>
        /// 定义枚举 获取值值值商品分类
        /// </summary>
        public enum zhizhizhiType
        {
            数码电脑 = 1,
            数码手机 = 2,
            家用电器 = 3,
            服饰鞋包 = 4,
            钟表饰品礼品 = 5,
            美容健康 = 6,
            母婴玩具 = 7,
            居家百货 = 9,
            食品保健品 = 10,
            运动户外 = 11,
            音像软件 = 14,
            书籍图书 = 14,
            其他分类 = 16
        }
        /// <summary>
        /// 定义枚举 获取今日聚超值商品分类
        /// </summary>
        public enum jrjczType
        {
            办公设备 = 1,
            电脑数码 = 2,
            家用电器 = 3,
            服饰鞋包 = 4,
            礼品钟表 = 5,
            个护化妆 = 6,
            母婴用品 = 7,
            家居家装 = 8,
            日用百货 = 9,
            食品保健 = 10,
            运动户外 = 11,
            汽车用品 = 12,
            玩模乐器 = 13,
            图书音像 = 14,
            其他 = 16
        }
        /// <summary>
        /// 定义枚举 获取 买个便宜货 商品分类
        /// </summary>
        public enum mgpyhType
        {
            电脑办公 = 1,
            手机数码 = 2,
            家用电器 = 3,
            服饰鞋包 = 4,
            钟表首饰 = 5,
            个护化妆 = 6,
            母婴玩具 = 7,
            家居家装 = 8,
            日用百货 = 9,
            食品饮料 = 10,
            运动户外 = 11,
            汽车用品 = 12,
            玩模乐器 = 13,
            图书音像 = 14,
            其他 = 16
        }
        /// <summary>
        /// 根据详细内容和正则表达式获取商品分类 
        /// </summary>
        /// <param name="detaiHtml"></param>
        /// <param name="regexStr"></param>
        /// <param name="type"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public long? GetProductTypeId(string detaiHtml, string regexStr, Type type, int index)
        {
            long? id = null;
            try
            {
                var labelContent = CustomMethod.GetInfoByRegex(regexStr, detaiHtml, index);
                if (labelContent != null && labelContent.Count > 0)
                {
                    var labelhref = CustomMethod.GetInfoFroma(labelContent[0]);
                    if (labelhref != null && labelhref.Count > 0)
                    {
                        //匹配商品类别
                        for (int number = 1; number < labelhref.Count; number = number + 2)
                        {
                            try
                            {
                                if (labelhref[number] == "3C数码")
                                {
                                    labelhref[number] = "C数码";
                                }
                                string cuItem = labelhref[number].Replace("&amp;", "").Trim();
                                var itme = Enum.Parse(type, cuItem);
                                id = Convert.ToInt64(itme);
                                break;
                            }
                            catch
                            {
                                continue;
                            }
                        }
                        if (id == null)
                        {
                            id = 16;
                        }
                    }
                    else
                    {
                        id = 16;
                    }
                }
                else
                {
                    id = 16;
                }
                return id;
            }
            catch (Exception ex)
            {
                CustomMethod.WriteLog("GetProductTypeId:" + type.Name.ToString() + ":" + ex.Message.ToString());
                return 16;
            }
        }

        /// <summary>
        /// 获取span 标签中的商品分类
        /// </summary>
        /// <param name="detaiHtml"></param>
        /// <param name="regexStr"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static long? GetProductType(string typeStr, Type type)
        {
            long? id = null;
            try
            {

                try
                {
                    if (typeStr == "3C数码")
                    {
                        typeStr = "C数码";
                    }
                    var itme = Enum.Parse(type, typeStr);
                    id = Convert.ToInt64(itme);
                }
                catch
                {
                    id = 16;
                }
                return id;
            }
            catch (Exception ex)
            {
                CustomMethod.WriteLog("GetProductTypeId:" + type.Name.ToString() + ":" + ex.Message.ToString());
                return 16;
            }
        }
        /// <summary>
        /// 获取span 标签中的商品分类
        /// </summary>
        /// <param name="detaiHtml"></param>
        /// <param name="regexStr"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public long? GetProductTypeId(string detaiHtml, string regexStr, Type type)
        {
            long? id = null;
            try
            {
                var labelContent = CustomMethod.GetInfoByRegex(regexStr, detaiHtml, 1);
                if (labelContent.Count > 0)
                {
                    //匹配商品类别
                    for (int number = 0; number < labelContent.Count; number++)
                    {
                        try
                        {
                            var itme = Enum.Parse(type, labelContent[number]);
                            id = Convert.ToInt64(itme);
                            break;
                        }
                        catch
                        {
                            continue;
                        }
                    }
                    if (id == null)
                    {
                        id = 16;
                    }
                }
                else
                {
                    id = 16;
                }
                return id;
            }
            catch (Exception ex)
            {
                CustomMethod.WriteLog("GetProductTypeId:" + type.Name.ToString() + ":" + ex.Message.ToString());
                return 16;
            }
        }
    }
}
